<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/12/17
 * Time: 20:08
 */

class UploadImages_control extends MY_Controller
{
    function index()
    {
        $body = $this->input->post();
        if ($this->test()) {
            $this->load->model('asset/uploadimages_model', 'upload');
            $id = $this->upload->memory_images($_FILES["file"]["name"]);
            $tmp = array('id' => $id, 's' => $body['s']);
            echo json_encode($tmp);
        }
    }

    public function test()
    {
        $upload_file = iconv("UTF-8", "GB2312", $_FILES["file"]["name"]);
        if (file_exists("upload/" . $upload_file)) {
            //文件重名，文件已存在
            return true;
        } else {
            $result = move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $upload_file);
            if ($result) {
                //文件上传成功
                return true;
            } else {
                header($this->config->item('http_status')[304]);
                return false;
            }
        }
    }
}